<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>添加或编辑界面</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
    <style>
        .w440 {
            width: 440px !important;
        }
    </style>
</head>
<body>
<div class="page-content-wrap clearfix">
    <form class="layui-form" id="tool">
        <input type="hidden" name="applyId" value="${applyId}" />
        <div class="layui-tab">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;工号：</label>
                        <div class="layui-input-inline w440">
                            <input type="text" name="userNumber" value="${wxEducationUser.userNumber}" lay-verify="required|loginName" placeholder="请输入工号" autocomplete="off"
                                   class="layui-input" maxlength="100">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;真实姓名：</label>
                        <div class="layui-input-inline w440">
                            <input type="text" name="name" value="${wxEducationUser.name}" lay-verify="required" placeholder="请输入真实姓名" autocomplete="off"
                                   class="layui-input" maxlength="100">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;手机号码：</label>
                        <div class="layui-input-inline w440">
                            <input type="text" name="mobile" value="${wxEducationUser.mobile}" lay-verify="required|phone" placeholder="请输入手机号码" autocomplete="off"
                                   class="layui-input" maxlength="11">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;员工类型：</label>
                        <div class="layui-input-inline w440">
                            <select name="userType" id="userType" lay-verify="required"></select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;有效状态：</label>
                        <div class="layui-input-inline w440">
                            <select name="status" id="status" lay-verify="required"></select>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 0px !important;text-align: center">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', 'page', 'baseutil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            page = layui.page,
            baseutil = layui.baseutil;

        var id = '${wxEducationUser.id}';

        page.initDict('wx_education_user_type,base_status', function (dictData) {
            page.showDict($("#userType"), page.aceeptDictContentList(dictData, 'wx_education_user_type'), "请选择", '${wxEducationUser.userType}');
            page.showDict($("#status"), page.aceeptDictContentList(dictData, 'base_status'), "请选择", '${wxEducationUser.status}');
        });

        form.verify({
            loginName: function (value) {
                if (!verifyLoginName(value)) {
                    return "您输入的工号已存在,请重新输入";
                }
            }
        });

        function verifyLoginName(userNumber) {
            var resCode=true;
            $.ajax({
                type : "post",
                url : "/wx/wxeducationuser/checkUserNumberUnique",
                data : {id:id, userNumber:userNumber},
                async : false,
                success : function(data){
                    if (data.code == 0){
                        resCode=false;
                    }
                }
            });
            if(!resCode){
                return false;
            }
            return true;
        }

        //监听提交
        form.on('submit(submitBtn)', function (data) {
            data.field.id = '${wxEducationUser.id}';
            data.field.loginName = data.field.userNumber;
            baseutil.AjaxPostMark("/wx/wxeducationuser/addOrUpdate", data.field, function () {
                $("#save").click();
            });
            return false;
        });
    });
</script>
</body>
</html>